﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CoreGallery.Addins.Contracts;
using CoreGallery.Core.AddinMgr;

namespace CoreGallery.Core.UI
{
    /// <summary>
    /// Interaction logic for AddinItemUserControl.xaml
    /// </summary>
    public partial class AddinItemUserControl : UserControl
    {
        AddinInfo _addin;

        public AddinItemUserControl()
        {
            InitializeComponent();

            this.DataContextChanged += new DependencyPropertyChangedEventHandler(AddinItemUserControl_DataContextChanged);
            
        }

        void AddinItemUserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            _addin = this.DataContext as AddinInfo;
            if( _addin != null )
            {
                DisableButton.Content = (_addin.IsEnabled ? "Disable" : "Enable");
            }
        }


        private void OptionsButton_Click(object sender, RoutedEventArgs e)
        {
            if (_addin != null)
            {
                MessageBox.Show(_addin.AddinInstance.AboutText);
            }
        }

        private void DisableButton_Click(object sender, RoutedEventArgs e)
        {
            if (_addin != null)
            {
                if( _addin.IsEnabled ) AddinManager.GetInstance().DisableAddin(_addin);
                else AddinManager.GetInstance().EnableAddin(_addin);
                
                DisableButton.Content = (_addin.IsEnabled ? "Disable" : "Enable");
                MessageBox.Show("This will take effect on next application restart");
            }
        }

        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            if (_addin != null)
            {
                AddinManager.GetInstance().RemoveAddin(_addin);
                MessageBox.Show("This will take effect on next application restart");
            }
        }
    }
}
